require "date" require "json" require "open-uri" require "uri" year = 2022 regexp = Regexp.new("\\A#{year}-\\d{2}-\\d{2} \\w{3} : .+\\z") pages = [] (1..12).each { |month| year_month = Date.new(year, month).strftime("%Y年%m月") url = "https://scrapbox.io/api/pages/june29/#{URI.encode_www_form_component(year_month)}" diary = JSON.parse(URI.open(url).read) diary["relatedPages"]["links1hop"].select { |page| regexp.match?(page["title"]) }.each { |page| pages << page } } counter = Hash.new(0) puts "日記 #{year}" pages.sort_by { |page| page["title"] }.each { |page| puts " [#{page["title"]}]" page["linksLc"].map { |word| word.gsub("_", " ") }.each { |word| counter[word] += 1 } } puts puts "table:links" counter.select { |_, count| count >= 3 }.sort_by { |_, count| count }.reverse.each { |word, count| puts "\t#{count}\t#{word}" } puts puts "code:script.rb" puts File.read(__FILE__).split("\n").map { |line| " #{line}" }